<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="{$_C.hy_path}css/amazeui.min.css" />
		<link rel="stylesheet" type="text/css" href="{$_C.hy_path}css/hy.admin.css" />
	</head>

	<body>
		<div class="am-g">
			{include file='../Common/hy_header.html'}
			<div class="am-u-md-8 am-u-end">
				<form class="am-form am-form-horizontal hy-js-form">
					<div class="am-form-group">
						<label for="user-name" class="am-u-sm-3 am-form-label">标题:</label>
						<div class="am-u-sm-9">
							<input type="text" name="name" value="{$rule.name}" placeholder="选填">
						</div>
					</div>
					{if $action=='create_rule'}
					<div class="am-form-group">
						<label for="user-name" class="am-u-sm-3 am-form-label">关键词:</label>
						<div class="am-u-sm-9">
							<input type="text" name="keyword" value="{$rule.keyword}" placeholder="选填">
						</div>
					</div>
					<div class="am-form-group">
						<label for="user-name" class="am-u-sm-3 am-form-label">类型:</label>
						<div data-am-button class="am-btn-group am-u-sm-9 hy-js-menutab">
							<label data-target="#link1" class="hy-js-menubtn am-btn am-btn-default am-btn-xs {if $rule.type}{if $rule.type eq 1} am-active {else}{/if}{else} am-active {/if} ">
								<input type="radio" {if $rule.type}{if $rule.type eq 1} checked="checked" {else}{/if}{else} checked="checked" {/if} name="type" value="1" id="option1">文字
							</label>
							<label data-target="#link2" class="hy-js-menubtn am-btn am-btn-default am-btn-xs {if $rule.type eq 2} am-active {else}{/if} ">
								<input type="radio" name="type" {if $rule.type eq 2} checked="checked" {else}{/if} value="2" id="option2"> 图文
							</label>
						</div>
					</div>
					{/if}
					<div id="link1" {if $rule.type}{if $rule.type eq 1}style="" {else}style="display:none;" {/if}{else}style="" {/if} class="hy-js-menupanel am-form-group">
						<div class="am-form-group">
							<label for="user-name" class="am-u-sm-3 am-form-label">内容:</label>
							<div class="am-u-sm-9">
								<textarea rows="3" name="content">{$rule.content}</textarea>
							</div>
						</div>
					</div>
					<div id="link2" {if $rule.type eq 2}style="" {else} style="display:none" {/if} class="hy-js-menupanel am-form-group">
						<div class="am-tabs am-margin" data-am-tabs="">
							<ul class="am-tabs-nav am-nav am-nav-tabs am-u-sm-9 am-u-sm-offset-3 hy-js-imgtab">
								<li data-id='1' class="am-active"><a hidefocus="true" href="#tab1">新增 <span class="am-icon-plus hy-js-addimg"></span></a>
								</li>
								{foreach from=$rule.pic_img name=img item=img} {if $smarty.foreach.img.index!=0}
								<li data-id='{$smarty.foreach.img.iteration}' class="am-active"><a hidefocus="true" href="#tab{$smarty.foreach.img.iteration}">图文{$smarty.foreach.img.iteration}<span data-id="{$img.id}" class="am-icon-close hy-js-closetab"></span></a>
								</li>
								{/if} {/foreach}
							</ul>
							<!--list  -->

							<div class="am-tabs-bd  am-u-sm-9 am-u-sm-offset-3 hy-js-imgarea">
								{if $rule.pic_img} {foreach from=$rule.pic_img name=img item=img}
								<div class="am-tab-panel am-fade am-active am-in" id="tab{$smarty.foreach.img.iteration}">
									<div class="am-form-group">
										<label for="user-name" class="am-u-sm-2 am-form-label">标题:</label>
										<div class="am-u-sm-10">
											<input type="text" name="field{$smarty.foreach.img.iteration}" value="{$img.title}">
										</div>
									</div>
									<div class="am-form-group">
										<label for="user-name" class="am-u-sm-2 am-form-label">描述:</label>
										<div class="am-u-sm-10">
											<textarea name="field{$smarty.foreach.img.iteration}" rows="3" cols="">{$img.description}</textarea>
										</div>
									</div>
									<div class="am-form-group">
										<label for="user-name" class="am-u-sm-2 am-form-label">链接:</label>
										<div class="am-u-sm-6">
											<input type="text" name="field{$smarty.foreach.img.iteration}" value="{$img.url}">
										</div>
										<div class="am-u-sm-4">
											<select class="hy-js-linkart">
												<option value="0">关联本站文章</option>
												{foreach from=$art_list item=list}
												<option value="{$list.url}">{$list.title}</option>
												{/foreach}
											</select>
										</div>
									</div>
									<div class="am-form-group">
										<label for="user-name" class="am-u-sm-2 am-form-label">缩略图:</label>
										<div class="am-u-sm-6">
											<input type="text" name="field{$smarty.foreach.img.iteration}" class="am-input-sm img-js-imgurl" value="{$img.thumb}">

										</div>
										<div class="am-u-sm-2">
											<img id="hy-thumb" class="hy-thumb" style="height: 30px;" {if $img.thumb}src="{$img.thumb}" {else} src="{$_C.hy_path}images/logo2.png" {/if}>
										</div>
										<div class="am-u-sm-2">
											<button class="am-btn am-btn-primary am-btn-xs hy-js-uploadimg">上传</button>
										</div>
									</div>
										<input type="hidden" name="field{$smarty.foreach.img.iteration}"  value="{$img.id}" />
								</div>
							
								{/foreach} {else}
								<div class="am-tab-panel am-fade am-active am-in" id="tab1">
									<div class="am-form-group">
										<label for="user-name" class="am-u-sm-2 am-form-label">标题:</label>
										<div class="am-u-sm-10">
											<input type="text" name="field" value="">
										</div>
									</div>
									<div class="am-form-group">
										<label for="user-name" class="am-u-sm-2 am-form-label">描述:</label>
										<div class="am-u-sm-10">
											<textarea name="field" rows="3" cols=""></textarea>
										</div>
									</div>
									<div class="am-form-group">
										<label for="user-name" class="am-u-sm-2 am-form-label">链接:</label>
										<div class="am-u-sm-6">
											<input type="text" name="field" value="">
										</div>
										<div class="am-u-sm-4">
											<select class="hy-js-linkart">
												<option value="0">关联本站文章</option>
												{foreach from=$art_list item=list}
												<option value="{$list.url}">{$list.title}</option>
												{/foreach}
											</select>
										</div>
									</div>
									<div class="am-form-group">
										<label for="user-name" class="am-u-sm-2 am-form-label">缩略图:</label>
										<div class="am-u-sm-6">
											<input type="text" name="field" class="am-input-sm img-js-imgurl" value="">

										</div>
										<div class="am-u-sm-2">
											<img id="hy-thumb" class="hy-thumb" style="height: 30px;"  src="{$_C.hy_path}images/logo2.png" >
										</div>
										<div class="am-u-sm-2">
											<button class="am-btn am-btn-primary am-btn-xs hy-js-uploadimg">上传</button>
										</div>
									</div>
								</div>
								{/if}
							</div>
						</div>
					</div>

					<div class="am-form-group">
						<div class="am-u-sm-9 am-u-sm-push-3">
							<input type="hidden" name="id" value="{$rule.id}" />
							<button type="button" class="am-btn am-btn-primary hy-js-submit">{$_L.SAVE}</button>
						</div>
					</div>
				</form>
			</div>
		</div>
		{include file='../Common/hy_footer.html'}
		<script type="text/javascript" src="{$_C.hy_path}js/editor/kindeditor.js"></script>
		<script type="text/javascript">
			$('.hy-js-imgtab li').live('click',function(){
			    	 $('.hy-js-imgtab li').removeClass('am-active');
			    	$(this).addClass('am-active');
			    	
			    })
			     $('.hy-js-imgtab a').live('click',function(e){
			     	e.preventDefault();
			     	
			    	var tab=$(this).attr('href');
			    	
			    	var hasclass=$(tab).hasClass('am-active am-in');
			    	console.log(hasclass);
			    	if(!hasclass)
			    	{
			    		$('.am-tabs-bd .am-tab-panel').each(function(){
			    			$(this).removeClass('am-active am-in');
			    		});
			    		$(tab).addClass('am-active am-in');
			    	}
			    });
			    $('.hy-js-linkart').live('change',function(){
			    	$(this).parent().parent().find('input').val($(this).val());
			    });
			    
			    $('.hy-js-closetab').live('click',function(){
			    	var tab=$(this).parent('a').attr('href');
			    	if(confirm('你确定要删除这条图文吗？'))
			    	{
			    		if(typeof($(this).attr('data-id'))!='undefined')
			    		{
			    			var id=$(this).attr('data-id');
			    			$.post('index.php?g=admin&m=wxrule&a=delimg',{ id:id},function(result){
			    				if(result.error==0)
			    				{
			    					$(this).parent('a').parent('li').remove();
			    	                $(tab).remove();
			    				}
			    				else
			    				{
			    					showMsg($result.content,1);
			    				}
			    			},'json')
			    		}
			    	   $(this).parent('a').parent('li').remove();
			    	   $(tab).remove();
			    	}
			    	
			    })
				hy_uploadimg('/rule', {}, function(result,_this) {
					if (typeof(result[0]) != 'undefined') {
						_this.parent().parent().find('.hy-thumb').attr('src', result[0]);
						_this.parent().parent().find('.img-js-imgurl').val(result[0]).focus();
					}
				});
				
				 hy_submit('index.php?g=admin&m=wxrule&a={$action}');
				 
				 $('.hy-js-addimg').click(function(){
				 	var num=1;
				 	$('.hy-js-imgtab li').each(function(){
				 		num=$(this).attr('data-id')>num?$(this).attr('data-id'):num;
				 	})
				 	num++;
				 	var art_list=$('.hy-js-linkart').html();
				 	var html='<div class="am-tab-panel am-fade" id="tab'+num+'">';
				 	    html+='<div class="am-form-group"><label for="user-name" class="am-u-sm-2 am-form-label">标题:</label><div class="am-u-sm-10"><input type="text" name="field'+num+'" value=""></div></div>';
				 	    html+=' <div class="am-form-group"><label for="user-name" class="am-u-sm-2 am-form-label">描述:</label><div class="am-u-sm-10"><textarea name="field'+num+'" rows="3" cols=""></textarea></div></div>';
				 	    html+='<div class="am-form-group"><label for="user-name" class="am-u-sm-2 am-form-label">链接:</label><div class="am-u-sm-6"><input type="text" name="field'+num+'" value=""></div><div class="am-u-sm-4"><select class="hy-js-linkart">'+art_list+'</select></div></div>';
				 	    html+='<div class="am-form-group"><label for="user-name" class="am-u-sm-2 am-form-label">缩略图:</label><div class="am-u-sm-6"><input type="text" name="field'+num+'" class="am-input-sm img-js-imgurl" value=""></div><div class="am-u-sm-2"><img id="hy-thumb'+num+'" class="hy-thumb" style="height: 30px;" src="{$_C.hy_path}images/logo2.png"></div> <div class="am-u-sm-2"><button class="am-btn am-btn-primary am-btn-xs hy-js-uploadimg" >上传</button></div></div>';
				 	    html+='</div>';
				 	  var tab='<li data-id="'+num+'" class=""><a hidefocus="true" href="#tab'+num+'">图文'+num+' <span class="am-icon-close hy-js-closetab"></span></a>';
				 	$('.hy-js-imgtab').append(tab);
				 	$('.hy-js-imgarea').append(html);
				 	
				 });
		</script>

	</body>

</html>